<template>
  <Table filter v-bind="tableOpts" v-on="tableEvent">
    <template #operator>
      <div class="operator-wrap"></div>
    </template>
  </Table>
</template>

<script>
import dayjs from "dayjs";
import tableMixins from "@/mixins/tableMixins.vue";
export default {
  name: "InventoryInventoryAlarmList",
  mixins: [tableMixins],
  components: {},
  // meta: { title: "告警列表", icon: "el-icon-s-flag", sort: 42 },
  data() {
    return {
      apiName: "inventoryInventoryAlarmList",
      form: {
        materialId: {
          tag: "el-select",
          label: "材料",
          value: "",
          items: [],
          props: {
            clearable: true,
            filterable: true,
          },
        },
        warehouseId: {
          tag: "el-select",
          label: "仓库",
          value: "",
          items: [],
          props: {
            clearable: true,
            filterable: true,
          },
        },
      },
    };
  },
  mounted() {
    this.$api["materialMaterialList"]({ pageSize: 10000,pageNumber:1 }).then((res) => {
      this.form.materialId.items = res?.rows.map((e) => ({
        label: `${e.materialName} ${e.color} ${e.norm}`,
        value: `${e.materialId || i}`,
      }));
      this.formKey = this.$quinn.guid();
    });
    this.$api["warehouseWarehouseList"]({ pageSize: 10000 }).then((res) => {
      this.form.warehouseId.items = res?.rows.map((e) => ({
        label: e.warehouseName,
        value: e.warehouseId,
      }));
      this.formKey = this.$quinn.guid();
    });
  },
  methods: {
    formatData(res) {
      this.total = res?.count || res?.total || 0;
      this.dataSource = (res?.rows || res?.data || res || []).map((e) => {
        if (e.updatedAt)
          e.updatedTime = dayjs(e.updatedAt).format("YYYY-MM-DD HH:mm:ss");
        if (e.createdAt) {
          e.createdTime = dayjs(e.createdAt).format("YYYY-MM-DD HH:mm:ss");
        }
        e.warehouseName = e?.warehouse?.warehouseName;
        return {
          ...e.material,
          ...e,
        };
      });
    },
    handleAction(opts, row) {
      const { supplierName: name, supplierId } = row;
      if (["edit"].includes(opts)) this.showDialog(opts, row);
      else if (opts === "delete")
        this.showConfirm(`确认删除【${name}】？`, "supplierSupplierDelete", {
          supplierId,
        });
      else {
        const ref = this.$refs[opts];
        ref && ref.showDialog(opts, row);
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
